package com.bsh.api;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.bsh.service.SysConfigService;
import com.bsh.utils.ApiMessage;
import com.bsh.utils.Des3;

/**
 * 验证相关API
 * 
 * @author gsh
 * @since 0.0.1
 * 
 */
@Controller
public class ApiConfiguration {
	private static Logger log = LoggerFactory.getLogger(ApiConfiguration.class);
	@Autowired
	HttpServletRequest request;
	@Autowired
	HttpServletResponse response;
	@Autowired
	HttpSession session;
	@Autowired
	SysConfigService sysCfg;


	/**
	 * 版本更新IOS
	 * 
	 * @param loginName
	 * @param password
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/api/v1/ver/check", method = { RequestMethod.POST })
	@ResponseBody
	public ApiMessage login() throws Exception {
		ApiMessage msg = null;		
		JSONObject iosCfg = sysCfg.getIOSVersionConfig();
		if (iosCfg != null) {
			msg = new ApiMessage("200", "读取IOS版本信息成功！");
			msg.setData(Des3.encResponse(iosCfg));
		} else {
			msg = new ApiMessage("102", "读取IOS版本信息失败!");			
		}

		return msg;
	}

	/**
	 * 版本更新安卓
	 * 
	 * @param loginName
	 * @param password
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/api/v1/ver/check/android", method = { RequestMethod.POST })
	@ResponseBody
	public ApiMessage checkVersion() throws Exception {
		ApiMessage msg = null;		
		JSONObject androidCfg = sysCfg.getANDROIDVersionConfig();
		if (androidCfg != null) {
			msg = new ApiMessage("200", "读取ANDROID版本信息成功！");
			msg.setData(Des3.encResponse(androidCfg));
		} else {
			msg = new ApiMessage("102", "读取ANDROID版本信息失败!");			
		}

		return msg;
	}
}
